/*
 * Copyright (c) by HzJbbis
 * All rights reserved.
 */

package hzjbbis.framework.properties.struts;

import hzjbbis.framework.context.ContextFacade;
import hzjbbis.framework.context.UserContext;
import hzjbbis.framework.faps.Faps;
import hzjbbis.framework.properties.dao.SystemPropertiesDao;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 * @since 1.1
 * @author lix
 */
public class SaveCurrentSystemPropertiesAction extends Action {
	public static final Log logger = LogFactory
			.getLog(SaveCurrentSystemPropertiesAction.class);

	/**
	 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping,
	 *      org.apache.struts.action.ActionForm,
	 *      javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse)
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest req, HttpServletResponse resp) throws Exception {
		UserContext uc = ContextFacade.getUserContext(req);

		Faps faps = uc.parseFaps(req.getParameter("newSystemProperties"));

		SystemPropertiesDao.saveCurrentSystemProperties(uc, faps);

		if (logger.isDebugEnabled()) {
			logger.debug("new system properties" + uc.getSystemProperties());
		}

		return mapping.findForward("submitSuccess");
	}

}
